package cn.wolfcode.mp.web.controller;

import cn.wolfcode.mp.domain.Employee;
import cn.wolfcode.mp.service.IEmployeeService;
import cn.wolfcode.mp.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/employees")
public class EmployeeController {
    @Autowired
    private IEmployeeService employeeService;

    @GetMapping("/list")
    public List<Employee> list() {
        return employeeService.list();
    }

    @PostMapping("/add")  //post增   put改
    public JsonResult add(Employee employee) {
        employeeService.save(employee);
        return JsonResult.success();
    }

    @GetMapping("/selectById")  //post增   put改
    public Employee selectById(Long id) {
        Employee employee = employeeService.getById(id);
        return employee;
    }

    @PutMapping("/update")  //post增   put改
    public JsonResult update(Employee employee) {
        employeeService.updateById(employee);
        return JsonResult.success();
    }

    @DeleteMapping("/delete")  //post增   put改
    public JsonResult delete(Long id) {
        employeeService.removeById(id);
        return JsonResult.success();
    }

}
